<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Testing websockets</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/printhtml/printhtml.js"></script>
</head>
<body>
  <div>
    <input type="button" value="打印1" onclick="start1();" />
	<input type="button" value="打印2" onclick="start2();" />
  </div>
  <div id="messages"></div>
  <script type="text/javascript">
    var webSocket = 
      initPrintHtml('ws://192.168.1.27:1819');

    webSocket.onerror = function(event) {
      onError(event)
    };

    webSocket.onopen = function(event) {
      onOpen(event)
    };

    webSocket.onmessage = function(event) {
      onMessage(event)
    };

    function onMessage(event) {
      document.getElementById('messages').innerHTML 
        += '<br />' + event.data;
    }

    function onOpen(event) {
      document.getElementById('messages').innerHTML 
        = 'Connection established';
    }

    function onError(event) {
      alert(event.data);
    }

    function start1() {
	  //printHtml(webSocket,"123233","https://www.datatables.net/","Brother MFC-7340 Printer",DMPAPER_A4,DMORIENT_PORTRAIT);
	  printHtml(webSocket,newGuid(),"https://www.datatables.net/","Brother MFC-7340 Printer",DMPAPER_A5,DMORIENT_PORTRAIT);
      return false;
    }
	function start2() {
	  printHtml(webSocket,newGuid(),"https://www.baidu.com","Microsoft XPS Document Writer",DMPAPER_A4,DMORIENT_PORTRAIT);
      return false;
    }
  </script>
</body>
</html>